<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Config;
use App\Models\Config as MConfig;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Tree;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Layout\Content;

class ConfigController extends AdminController
{
    public function index(Content $content)
    {
        return $content->header('全局参数')
            ->body(function (Row $row) {
                $tree = new Tree(new Config);
                $tree->expand(false);
                $row->column(12, $tree);
            });
    }
    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Config(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('pid');
            $show->field('listorder');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Config(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->text('fname');
            $form->select('pid')->options(MConfig::selectOptions())->default(0);

            $form->number('listorder')->default(0);
        });
    }
}
